<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../static/layuiadmin/layui/css/layui.css" tppabs="https://www.layui.site/layui/dist/css/layui.css" media="all">
    <script src="https://code.jquery.com/jquery-3.6.0.js"></script>

</head>
<body>
<br>
<div id="test2" class="demo-tree"></div>


<script src="../../static/layuiadmin/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>

    layui.use(["tree", 'util'], function () {

        var tree = layui.tree
        var data1 = [];
        $.ajax({
            type: "POST",
            url: "/ams-admin/dept/JsonTree",
            contentType: "application/json",
            success: function (r) {
                data1 = r
                //仅节点左侧图标控制收缩
                tree.render({
                    elem: '#test2'
                    , data: data1
                    , onlyIconControl: true  //是否仅允许节点左侧图标控制展开收缩
                    , click: function (obj) {
                        window.parent.$("#parentName").val(obj.data.label)
                        window.parent.$("#parent_id").val(obj.data.id)
                    }
                });
            }
        });
    });
</script>

</body>
</html>